#!/usr/bin/python
# -*- coding: utf-8 -*-

"""
Author: FQ
Module Description: prince_utils ... 
File: prince_utils.py
Date: 2019/3/5
"""
import math

from pyshare.dal.repository_impl import PrinceRepository, CrownPrinceRepository


class CrownPrince(object):
    """
    太子属性方法
    """

    @staticmethod
    def princes_aptitude_to_attribute(prince):
        """
        根据皇子资质计算属性
        update : 1.4版本更新皇子计算公式 系数2改成12
        :param prince: 皇子数据
        :return:
        """
        attribute = prince.learned_attribute
        for i in range(0, 4):
            attr_num = int(math.ceil((prince.study_level + 2)
                                     * (prince.study_level - 1)
                                     * prince.aptitude[i] * 0.1
                                     + prince.aptitude[i] * 12 + 10))
            attribute[i] += attr_num
        return attribute

    @classmethod
    def add_prince_attribute(cls, rid, attribute):
        """
        太子大臣增加对应皇子属性
        :param rid:
        :param attribute:太子大臣属性列表
        :return:
        """
        crown_prince_link = CrownPrinceRepository.get_by_rid(rid)
        if not crown_prince_link or not crown_prince_link.prince_id:
            return attribute
        prince = PrinceRepository.get_by_rid_prince_id(rid, crown_prince_link.prince_id)
        if not prince:
            return attribute
        prince_attribute = cls.princes_aptitude_to_attribute(prince)
        for i in range(4):
            attribute[i] += prince_attribute[i]
        return attribute